<?php


namespace app\listener;


use app\data\model\Remind;
use app\mall_back\model\GoodsLuckyDrawModel;

class WinningRemind
{
    public function handle($goods_lucky_draw_id){
        if($goods_lucky_draw_id){
            $goodsLuckyDraw = GoodsLuckyDrawModel::with(['goods'])->find($goods_lucky_draw_id);
        }
        if($goodsLuckyDraw && $goodsLuckyDraw['winning_user_id'] && $goodsLuckyDraw['is_draw_a_lottery']==1){
            $remingModel = new Remind();
            $is = $remingModel->where(['goods_lucky_draw_id'=>$goods_lucky_draw_id])->find();
            if(!$is){
                $remingModel->goods_lucky_draw_id = $goods_lucky_draw_id;
                $remingModel->create_time = date('Y-m-d H:i:s');
                $remingModel->user_id = $goodsLuckyDraw['winning_user_id'];
                $remingModel->lucky_number = $goodsLuckyDraw['award_number'];
                $remingModel->goods_name = $goodsLuckyDraw['goods']['goods_name'];
                $remingModel->save();
            }

        }

    }
}